package com.group9.handinhand.controller.form;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import com.group9.handinhand.service.so.CommunityMemberSO;
import com.group9.handinhand.service.so.CommunitySO;
import com.group9.handinhand.service.so.CommunityTagSO;
import com.group9.handinhand.service.so.EventSO;
import com.group9.handinhand.service.so.MembershipRequestSO;
import com.group9.handinhand.service.so.OfferSO;
import com.group9.handinhand.service.so.PostSO;
import com.group9.handinhand.service.so.RequestSO;
import com.group9.handinhand.service.so.UserSO;
import com.group9.handinhand.service.so.UserTagSO;
/**
 * 
 * @class CommunityViewForm
 *
 */
public class CommunityViewForm {
	/**
	 * A user service object.
	 * */
	UserSO user;
	/**
	 * User tag list.
	 */
	List<UserTagSO> userTags;
	/**
	 * a list which consist of community tag service object.
	 */
	List<CommunityTagSO> communityTags;
	CommunitySO community;
	CommunitySO moderatedCommunity;/**/
	CommunityMemberSO communityMember;/**/
	MembershipRequestSO membershipRequest;/**/
	String post;/**/
	ArrayList<Object> wallElements = new ArrayList<Object>();
	ArrayList<Object> commList = new ArrayList<Object>();
	/**
	 * A setter method.
	 * Sets the events request offers and the posts of the community
	 */
	public void setWallElementsFromCommunity(){
		wallElements.addAll(community.getEvents());
		wallElements.addAll(community.getRequests());
		wallElements.addAll(community.getOffers());
		wallElements.addAll(community.getPosts());
		Collections.sort(wallElements, new Comparator<Object>() {
			public int compare(Object o1, Object o2) {
				Date o1createDate = (o1 instanceof EventSO)?((EventSO)o1).getCreateDate(): (
						(o1 instanceof RequestSO)?((RequestSO)o1).getCreateDate():(
								(o1 instanceof OfferSO)?((OfferSO)o1).getCreateDate():(
									(o1 instanceof PostSO)?((PostSO)o1).getCreateDate():null)
									)
								);
						
				Date o2createDate = (o2 instanceof EventSO)?((EventSO)o2).getCreateDate(): (
						(o2 instanceof RequestSO)?((RequestSO)o2).getCreateDate():(
								(o2 instanceof OfferSO)?((OfferSO)o2).getCreateDate():(
									(o2 instanceof PostSO)?((PostSO)o2).getCreateDate():null)
									)
								);
				if (o1createDate == null || o2createDate == null)
					return 0;
				return o2createDate.compareTo(o1createDate);
			}
		});
	}
	/**
	 * A getter method.
	 * @return membershipRequest
	 */
	public MembershipRequestSO getMembershipRequest() {
		return membershipRequest;
	}
	/**
	 * A setter method.
	 * @param membershipRequest
	 */
	public void setMembershipRequest(MembershipRequestSO membershipRequest) {
		this.membershipRequest = membershipRequest;
	}
	/**
	 * getter method
	 * @return moderatedCommunity
	 */
	public CommunitySO getModeratedCommunity() {
		return moderatedCommunity;
	}

	/**
	 * A setter method.
	 * @param moderatedCommunity
	 */

	public void setModeratedCommunity(CommunitySO moderatedCommunity) {
		this.moderatedCommunity = moderatedCommunity;
	}


	/**
	 * A getter method
	 * @return community
	 */
	public CommunitySO getCommunity() {
		return community;
	}
	/**
	 * A getter method
	 * Gets the post on the community
	 * @return post
	 */
	public String getPost() {
		return post;
	}
	/**
	 * A setter method.
	 * Sets the post
	 * @param post
	 */
	public void setPost(String post) {
		this.post = post;
	}
	/**
	 * A setter method.
	 * @param community
	 */
	public void setCommunity(CommunitySO community) {
		this.community = community;
	}
	/**
	 * A getter method.
	 * @return communityMember
	 */
	public CommunityMemberSO getCommunityMember() {
		return communityMember;
	}
	/**
	 * A setter method.
	 * @param communityMember
	 */
	public void setCommunityMember(CommunityMemberSO communityMember) {
		this.communityMember = communityMember;
	}
	/**
	 * A getter method.
	 * @return the elements on the wall
	 */
	public ArrayList<Object> getWallElements() {
		return wallElements;
	}
	/**
	 * A setter method
	 * @param wallElements
	 */
	public void setWallElements(ArrayList<Object> wallElements) {
		this.wallElements = wallElements;
	}
	/**
	 * A getter method.
	 * 
	 * @return user
	 */
	public UserSO getUser() {
		return user;
	}
	/**
	 * A setter method.
	 * @param user
	 */
	public void setUser(UserSO user) {
		this.user = user;
	}
	/**
	 * A getter method.
	 * @return userTags
	 */
	public List<UserTagSO> getUserTags() {
		return userTags;
	}
	
	/**
	 * A setter method
	 * @param userTags
	 */
	public void setUserTags(List<UserTagSO> userTags) {
		this.userTags = userTags;
	}
	/**
	 * A getter method.
	 * @return communityTags
	 */
	public List<CommunityTagSO> getCommunityTags() {
		return communityTags;
	}
	/**
	 * A setter method.
	 * @param communityTags
	 */
	public void setCommunityTags(List<CommunityTagSO> communityTags) {
		this.communityTags = communityTags;
	}
	
	/**
	 * A getter method.
	 * @return list of the communities
	 */
	public ArrayList<Object> getCommList() {
		return commList;
	}
	/**
	 * A setter method.
	 * @param commList
	 */
	public void setCommList(ArrayList<Object> commList) {
		this.commList = commList;
	}
	/**
	 * To string method which convert CommunityVievForm class to a string.
	 */
	@Override
	public String toString() {
		return "CommunityViewForm [community=" + community
				+ ", moderatedCommunity=" + moderatedCommunity
				+ ", communityMember=" + communityMember + ", post=" + post
				+ ", wallElements=" + wallElements + "]";
	}
	

	
	

}
